﻿@using CoralNode.Core.Entity.Model
@{
    Layout = null;
    LinkMenuModel linkMenuModel = Newtonsoft.Json.JsonConvert.DeserializeObject<LinkMenuModel>(Model.LinkUrl);
}
<form id="spform" action="/m/menu/editMenu/@Model.Id" method="post" enctype="multipart/form-data">
    @if (@ViewBag.Msg != null) {
        <div class="error_msg">
            @ViewBag.Msg.Msg
        </div>
    }
    <div class="pt_3 js_tabcnt">
        <div class="table_form form_main ">
            <div class="pl_2 pb_3">
                <table>
                    <tbody class="menuType">
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)
                        <tr style="position: relative; z-index: 2;">
                            <th width="100">
                                <label class="js_link_menu">
                                    <input type="radio" name="linkMenu.LinkType" class="mt_0-5 mr_0-5" value="2" @(linkMenuModel.LinkType == LinkType.Menu ? "checked='checked'" : string.Empty)>跳转到菜单：</label>
                            </th>
                            <td>
                                <div class="ztreeContainer">
                                    <input type="text" name="" class="text w_37" value="@(linkMenuModel.LinkType == LinkType.Menu && linkMenuModel.Menu != null ? linkMenuModel.Menu.Title : "")">
                                    <input type="hidden" value="@(linkMenuModel.LinkType == LinkType.Menu && linkMenuModel.Menu != null ? linkMenuModel.Menu.Id : 0)" name="linkMenu.Value"><ul
                                        class="ztree"></ul>
                                </div>
                            </td>
                        </tr>
                        <tr style="position: relative; z-index: 1;">
                            <th width="60">
                                <label class="js_link_url">
                                    <input type="radio" name="linkMenu.LinkType" class="mt_0-5 mr_0-5" value="1"  @(linkMenuModel.LinkType == LinkType.Url ? "checked='checked'" : string.Empty)>跳转到网址：</label>
                            </th>
                            <td>
                                <input type="text" name="linkMenu.Value" class="text w_37" value="@(linkMenuModel.LinkType == LinkType.Url && !string.IsNullOrEmpty(linkMenuModel.Value) ? linkMenuModel.Value : "http://")">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

    </div>
    <div class="submitbox p_2 extra_normal">
        <input type="submit" class="btn_1" value="提    交" />
    </div>
</form>
<script>
    $(function () {
        $('form').submit(function (e) {
            e.preventDefault();
            var $this = $(this);
            $.post($this.attr("action"), $this.serialize(), function (data) {
                if (data != "") {
                    $.alert("修改成功");
                    setTimeout("$('.d-close').trigger('click')", 1000);
                }
            });
        });
        linkMenu();
        function linkMenu() {
            $(".js_link_menu,.js_link_url").click(function (e) {
                var $this = $(this),
                    $radio = $this.find("input");
                if ($radio.is(":checked")) {
                    $this.parents("tr").siblings("tr").find("th").find(".js_link_menu,.js_link_url").parent("th").siblings("td").find("input[type='text']").attr("disabled", "disabled");
                    $this.parents("th").siblings("td").find("input[type='text']").removeAttr("disabled");
                }
            });
            $(".js_link_menu").bind("click.trigger", function (e) {
                var $this = $(this);
                $this.unbind("click.trigger");
                $.post("/m/menu/GetCurrentMenuList/", { menuId: "@(linkMenuModel != null && linkMenuModel.Menu != null ? linkMenuModel.Menu.Id : 0)" }, function (data) {
                    var $ztreeContainer = $this.parents("th").siblings("td").find(".ztreeContainer");
                    $ztreeContainer.find("ul").zTreeInit({
                        data: data, trigger: $ztreeContainer.find("input[type='text']"), checkFun: function (treeNode) {
                            var showText = treeNode.name;
                            var tempNode = treeNode;
                            while (tempNode.getParentNode() != null) {
                                tempNode = tempNode.getParentNode();
                                showText = tempNode.name + " > " + showText;
                            }
                            $ztreeContainer.find("input[type='text']").val(showText);
                            $ztreeContainer.find("input[type='hidden']").val(treeNode.id);
                        }
                    })
                });
            });
            $(".js_link_menu,.js_link_url").find("input[type='radio']:checked").parent().trigger("click.trigger");
        }
    })
</script>
